package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import java.util.Optional;

import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.FeeSuitTypeAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;

/**
 * @ClassName : FeeSuitTypeAttrLinkHandler
 * @Description : 套包类型
 * @Author : xie.zhengjun
 * @Date : 2020/12/30 16:59
 */
@Service
@AttrHandler(FeeSuitTypeAttrHandler.class)
public class FeeSuitTypeAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {
    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        // 资费计划-资费服务- 套包类型 为 批量超套 时才展示 超套资费(元/M)且必填
        if (KiteStringUtils.isEqual(attr.getValue(), "100006436")) {
            Optional.ofNullable(inst.getAttr("200004030"))
                .ifPresent(kiteAttr -> {
                    kiteAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_M);
                    kiteAttr.setIsNull(KeyConsts.IFTRUE_F);
                });
        } else {
            Optional.ofNullable(inst.getAttr("200004030"))
                .ifPresent(kiteAttr -> {
                    kiteAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
                    kiteAttr.setIsNull(KeyConsts.IFTRUE_T);
                });
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
